import request from "@/utils/request";

//1.根据skuId上架商品
export const requestOnSale = (skuId: number) => {
    return request.get<any, null>(`/admin/product/onSale/${skuId}`);
};

//2.根据skuId下架商品
export const requestCancelSale = (skuId: number) => {
    return request.get<any, null>(`/admin/product/cancelSale/${skuId}`);
};

//3.删除sku
export const requestDeleteSku = (skuId: number) => {
    return request.delete<any, null>(`/admin/product/deleteSku/${skuId}`);
};

//sku图片列表每一项leix
export interface reqSkuImageListItemType {
    id?: number;
    skuId?: number;
    imgName: string;
    imgUrl: string;
    spuImgId?: number;
    isDefault: string;
}
//sku图片列表类型
export type reqSkuImageListType = reqSkuImageListItemType[];
//sku属性值列表每一项类型
export interface reqSkuAttrValueListItemType {
    id?: number;
    attrId?: number;
    valueId?: number;
    skuId?: number;
    attrName: string;
    valueName: string;
}
//sku属性值列表类型
export type reqSkuAttrValueListType = reqSkuAttrValueListItemType[];
//sku销售属性值列表每一项类型
export interface reqSkuSaleAttrValueListItemType {
    id?: number;
    skuId?: number;
    spuId?: number;
    saleAttrValueId?: number;
    saleAttrId?: number;
    saleAttrName: string;
    saleAttrValueName: string;
}
//sku销售属性值列表类型
export type reqSkuSaleAttrValueListType = reqSkuSaleAttrValueListItemType[];
//sku详细信息类型
export interface reqSkuInfoItemType {
    id?: number;
    spuId?: number;
    price: string;
    skuName: string;
    skuDesc: string;
    weight: string;
    tmId?: number;
    category3Id: number | null;
    skuDefaultImg: string;
    isSale: number;
    createTime: string;
    skuImageList: reqSkuImageListType | null;
    skuAttrValueList: reqSkuAttrValueListType | null;
    skuSaleAttrValueList: reqSkuSaleAttrValueListType | null;
}
//sku列表类型
export type reqSkuInfoListType = reqSkuInfoItemType[];
//sku分页列表类型
export interface reqSkuPageType {
    total: number;
    size: number;
    current: number;
    searchCount: boolean;
    pages: number;
    records: reqSkuInfoListType
}
//4.根据skuId获取它的sku列表
export const requestSkuInfoList = (spuId: number) => {
    return request.get<any, reqSkuInfoListType>(
        `/admin/product/findBySpuId/${spuId}`
    );
};
//5.根据skuId获取它的sku详细信息
export const requestSkuInfo = (skuId: number) => {
    return request.get<any, reqSkuInfoItemType>(
        `/admin/product/getSkuById/${skuId}`
    );
};
//6.获取sku分页列表
export const requestSkuPageList = (page:number,limit:number) => {
    return request.get<any,reqSkuPageType>(`/admin/product/list/${page}/${limit}`)
};
//7.新增sku
export const requestAddSku = (skuInfo:reqSkuInfoItemType) => {
    return request.post<any,null>('/admin/product/saveSkuInfo',skuInfo)
}
